package com.ixiaowo.springcouldconsumermovie.feign;

import com.ixiaowo.springcouldconsumermovie.entity.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * fallbackMonth的增强版
 */
@Component
public class WithHystrixFactory implements FallbackFactory<UserFeignClient>{
    private static final Logger LOGGER = LoggerFactory.getLogger(WithHystrixFactory.class);
    @Override
    public UserFeignClient create(Throwable throwable) {
        WithHystrixFactory.LOGGER.info("发生错误;啦..没连接到服务器",throwable.getMessage());
        return new UserHystrixFallBackFactory() {
            @Override
            public User findById(Long id) {
                User user = new User();
                user.setId(-1L);
                return user;
            }
        };
    }
}
